package com.caine.androidtask.ls07;

import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.caine.androidtask.R;

public class Ls07 extends Activity implements OnClickListener {

	private Button btn_create;
	private Button btn_insert;
	private Button btn_update;
	private Button btn_delete;
	private Button btn_selectall;
	private SQLiteHelper helper;
	private SQLiteDatabase database;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.caine_ls07);
		init();
	}

	void init() {
		btn_create = (Button) findViewById(R.id.btn_ctable);
		btn_insert = (Button) findViewById(R.id.btn_insert);
		btn_update = (Button) findViewById(R.id.btn_update);
		btn_delete = (Button) findViewById(R.id.btn_delete);
		btn_selectall = (Button) findViewById(R.id.btn_selectall);
		btn_create.setOnClickListener(this);
		btn_insert.setOnClickListener(this);
		btn_update.setOnClickListener(this);
		btn_delete.setOnClickListener(this);
		btn_selectall.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.btn_ctable:
			if (helper == null) {
				helper = new SQLiteHelper(this, "CaineZhu", 1, null);
			}else{
				System.out.println("SQLiteHelper is already init you don't init again!!!");
			}
			break;
		case R.id.btn_insert:			
		 database = helper.getWritableDatabase();
		 //database.insertOrThrow("TB_1", new String[]{"id","name"}, new String[]{"1","test"});
		 ContentValues values = new ContentValues();
		 values.put("id", 1);
		 values.put("name", "admin");
		 database.insert("TB_1", null, values);
			break;
		case R.id.btn_update:
			break;
		case R.id.btn_delete:
			break;
		case R.id.btn_selectall:
			break;
		default:
		}
	}
}